/**
 * 
 */
package com.gragra.evaluateFunctionWords;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Arrays;
import com.gragra.parseOptions.CommandLineException;
import com.gragra.parseOptions.Parser;
/**
 * @author Christoph Teichmann
 * created Apr 28, 2013 9:52:12 PM
 * @version 0.1
 */
public class EvaluateWordFrequencyMultiple
{
	/**
	 *
	 * @param args
	 * @throws CommandLineException 
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException
	{
		BufferedWriter bw = new BufferedWriter(new FileWriter(args[1]));
		bw.write("WordsUsed,Precision,Recall,F-Score");
		bw.newLine();
		args = Arrays.copyOfRange(args, 0, args.length+2);
		args[args.length-2] = "-nW";
		String[][] pairs = new String[][] {{"5"},{"10"},{"50"},{"100"},{"500"}};
		for(String[] pair : pairs)
		{
			args[args.length-1] = pair[0];
			System.out.println(Arrays.toString(args));
			Parser pr = new Parser();
			EvaluateFunctionsWithMapping efm = new EvaluateWordFrequencyFunctionsWithMapping();
			try
			{efm.addOptions(pr);}
			catch(CommandLineException e)
			{
				System.out.println("initialization error:");
				e.printStackTrace();
				System.exit(-1);
			}
			pr.setProgramDescription("This program is used to evaluate function word detection based purely on frequency");
			pr.setMinArgs(2);
			pr.setMaxArgs(2);
			pr.setArgumentDescription(0, "The name of the input file that will be used.");
			pr.setArgumentDescription(1, "The name of the output file to which results will be written.");
			try
			{pr.parse(args);}
			catch(CommandLineException e)
			{
				e.printStackTrace();
				System.out.println(pr.writeOutHelp());
				System.exit(-1);
			}
			if(pr.hadHelp())
			{
				System.out.println(pr.writeOutHelp());
				System.exit(0);
			}
			BufferedReader br = new BufferedReader(pr.getFileReaderFromArgument(0));
			double[] res = efm.evaluate(pr, br);
			DecimalFormat df = new DecimalFormat("#0.00");
			br.close();
			bw.write(pair[0]);
			bw.write(",");
			bw.write(df.format(res[0]).replaceAll(",", "."));
			bw.write(",");
			bw.write(df.format(res[1]).replaceAll(",", "."));
			bw.write(",");
			bw.write(df.format(res[2]).replaceAll(",", "."));
			bw.newLine();
		}
		bw.close();
	}
}